export class HideBtn {
    constructor(el, area) {
        this.$el = el;
        this.$area = area;
        this.scrollChange();
    }
    scrollChange() {
        let $area = this.$area;
        let $el = this.$el;
        let old_pos = 0;
        /*if(Object.prototype.toString.call($area.get(0))==='[object Window]') {
            bottom = document.body.scrollHeight-document.documentElement.clientHeight;
        } else {*/
        /*}*/
        $area.on('scroll', function () {
            let delta =  $area.scrollTop() - old_pos;
            /*let bottom = $area.get(0).scrollHeight-$area.get(0).clientHeight;*/
            let bottom = document.body.scrollHeight-document.documentElement.clientHeight;
            if(Math.abs(delta) < 20) {
                return false;//防止ios误触发
            } else if (old_pos < $area.scrollTop()) {
                $el.fadeOut(200);
            } else if ($area.scrollTop() < bottom - $('.comment').height() + 180){
                $el.fadeIn(200); 
            }
            setTimeout(function() {
                if($area.scrollTop() < 0) {
                    old_pos = 0;
                } else if ($area.scrollTop() > bottom) {
                    old_pos = bottom;
                }else {
                    old_pos = $area.scrollTop();
                }
            },0);
        });
    }
}

/*module.exports = HideBtn;*/
